int DFA(char *pattern, char *text)
{
  int m = strlen(pattern);
  int n = strlen(text);
  int i, j;
  
  //build DFA from pattern
  int **dfa = new(RADIT, m);
  dfa[(int) pattern[0]][0] = 1;
  for (i = 0, j = 1; j < m; ++j)
  {
    int c;
    for (c = 0; c < RADIT; ++c)
    {
      dfa[c][j] = dfa[c][i];
    }
    dfa[(int) pattern[j]][j] = j + 1;
    i = dfa[(int) pattern[j]][i];
  }
  
  //find pattern from text
  for (i = 0, j = 0; i < n && j < m; ++i)
  {
    j = dfa[(int) text[i]][j];
  }
  
  free(dfa[0]);
  free(dfa);
  
  if (j == m)
  {
    return i - m;
  }
  return -1;
}

